define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/ys/index' + location.search,
                    add_url: 'user/ys/add',
                    // edit_url: 'user/ys/edit',
                    // del_url: 'user/ys/del',
                    multi_url: 'user/ys/multi',
                    import_url: 'user/ys/import',
                    table: 'ys_exchange',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'sn', title: __('Sn'), operate: 'LIKE'},
                        {field: 'state', title: __('State'), searchList: {"1":__('State 1'),"2":__('State 2'),"3":__('State 3')}, formatter: Table.api.formatter.normal},
                        {field: 'ys', title: __('Ys'), operate:false},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                        buttons: [
                            {
                                name: 'audit',
                                title: '审核',
                                text: '审核',
                                refresh: true,
                                classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                url: 'user/ys/audit',//接口地址 控制器名/方法名
                                visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                    if (row.state =='1') {
                                        return true;//显示
                                    } else {
                                        return false;//隐藏
                                    }

                                },
                            },
                           
                        ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        audit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
